package com.zhejiangzhengyuan.municipal_common.service.impl;

import com.zhejiangzhengyuan.municipal_common.entity.InspectionRecord;
import com.zhejiangzhengyuan.municipal_common.entity.InspectionTasks;
import com.zhejiangzhengyuan.municipal_common.entity.dto.InspectionRecordTaskDto;

import org.springframework.stereotype.Component;


import javax.validation.constraints.NotBlank;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;


/**
 * @author lin_ju
 * Create on 2019/12/23
 */
@Component
public class InspectionDtoServiceImpl {


    //工具类没用好手动实现，有时间改
    public InspectionTasks dtoMapByInspectionTasks(InspectionRecordTaskDto dto) {
        InspectionTasks inspectionTasks = new InspectionTasks();
        if (dto.getType() != null) {
            inspectionTasks.setType(dto.getType());
        }
        if (dto.getStatus() != null) {
            inspectionTasks.setStatus(dto.getStatus());
        }
        if (dto.getStartTime() != null) {
            inspectionTasks.setStartTime(new Timestamp(dto.getStartTime().getTime()));
        }
        if (dto.getEndTime() != null) {
            inspectionTasks.setEndTime(new Timestamp(dto.getEndTime().getTime()));
        }
        if (dto.getEndTime() != null) {
            inspectionTasks.setEndTime(new Timestamp(dto.getEndTime().getTime()));
        }
        if (dto.getImmediatelyExecuteTime() != null) {
            inspectionTasks.setImmediatelyExecuteTime(new Timestamp(dto.getEndTime().getTime()));
        }
        if (dto.getReportTime() != null) {
            inspectionTasks.setReportTime(new Timestamp(dto.getReportTime().getTime()));
        }
        if (dto.getContext() != null) {
            inspectionTasks.setContext(dto.getContext());
        }
        if (dto.getTitle() != null) {
            inspectionTasks.setTitle(dto.getTitle());
        }
        if (dto.getInspectionCycleNumber() != null) {
            inspectionTasks.setInspectionCycleNumber(dto.getInspectionCycleNumber());
        }
        if (dto.getInspectionCycleType() != null) {
            inspectionTasks.setInspectionCycleType(dto.getInspectionCycleType());
        }
        return inspectionTasks;
    }


    public List<InspectionRecord> dtoMapByInspectionRecord(InspectionRecordTaskDto dto) {

        List<InspectionRecord> inspectionRecords = new ArrayList<>();
        @NotBlank String targetId =  dto.getTargetId();
        String[] split = targetId.split(",");
        for (String s : split) {
            InspectionRecord inspectionRecord = new InspectionRecord();
            inspectionRecord.setTargetId(s);
            if (dto.getId() != null) {
                inspectionRecord.setId(dto.getId());
            }
            if (dto.getInspectionUserInfoId()!=null){
                inspectionRecord.setInspectionUserInfoId(dto.getInspectionUserInfoId());
            }
            inspectionRecords.add(inspectionRecord);
        }
        return inspectionRecords;
    }

}
